package com.pap.rabbitmq.trans.listener;

import ch.qos.logback.core.net.SyslogOutputStream;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 事务控制私信队列的监听，此处可以日志记录，发送邮件进行人工介入，同时从持久化三方守护进程中删除记录
 * @Auther: alexgaoyh
 * @Date: 2018/12/3 16:05
 * @Description:
 */
@Component
public class TransDeadLetterMessageListener implements ChannelAwareMessageListener {

    @Override
    public void onMessage(Message message, Channel channel) throws Exception {
        MessageProperties messageProperties = message.getMessageProperties();
        // 消息体
        String messageBody = new String(message.getBody());

        // TODO logger messageBody, message.getMessageProperties().getDeliveryTag()
        // TODO 可以持久化和发送邮件，人工介入
        System.out.println("-------------please check data,send mail ---------------------------------------" + messageBody);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);

        // TODO 从定义的 DBCoordinator  中，删除当前的数据记录 messageProperties.getMessageId()
        // redisTemplate.opsForHash().delete(MQConstants.MQ_CONSUMER_RETRY_COUNT_KEY, messageProperties.getMessageId());
    }


}
